#include <bits/stdc++.h>
// 2025/02/26
// tag: 
// Author: Forever
using namespace std;

using int64 = int64_t;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    while (n--){
        string s;
        cin >> s;
        int cnt = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '1')
                cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}